package jpb.module.rest.member;

import jpb.constant.Reply;
import jpb.constant.ReturnState;
import jpb.module.daomain.member.Member;
import jpb.module.service.member.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by haol on 2017/4/8.
 */
@RestController
@RequestMapping("/api/web/member")
public class MemberWebController {
        @Autowired
        private MemberService memberService;


        /**
         * @api {GET} /api/web/member/i/{oid}  查看信息
         * @apiGroup MemberWeb
         * @apiName get
         * @apiDescription 查看成员的信息
         * @apiParam {String} memberNum 成员编号
         * @apiParamExample {json} 请求样例：
         * GET /api/web/member/i/organize_id?memberNum=201430098009
         * @apiSuccessExample {json} 返回样例:
         * {
         * "code":0,"msg":"成功","data":{"id":1,"name":"张睿浩","memberNum":"201430098009","createTime":"Thu Apr 20 16:55:35 CST 2017","updateTime":"Thu Apr 20 20:37:00 CST 2017","mobiles":["123456","123231221"]}
         * }
         */
        @RequestMapping(value = "/i/{oid}", method = RequestMethod.GET)
        public String get(@PathVariable String oid, String memberNum) {
                Member member = memberService.get(memberNum);
                Reply reply = null;
                if (member == null) {
                        reply = new Reply<Member>(1, ReturnState.NO_FIND);
                } else {
                        reply = new Reply<Member>(0, ReturnState.SUCCESS, member);
                }
                return reply.toJson();
        }


}
